﻿using System;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.UI;

public class NetVTuberArgs
{
   public int code;
   public int errorCode;
   public NetRecordArgs recordData;
}
public class NetRecordArgs
{
   public bool record = false;
   public string savePath = "";
}

public class UICanvas : MonoBehaviour
{
   public Button onBtn;
   public Button offBtn;
   
   public UISwitch switchBtn;
   public UIToggle toggleBtn;
   
   private void Awake()
   {
      onBtn.onClick.AddListener(OnBtnClick);
      offBtn.onClick.AddListener(OffBtnClick);
      // Text a = null;
      // a.lineSpacing
      toggleBtn.onValueChanged.AddListener(ToggleValueChanged); 
   }

   private void ToggleValueChanged(bool arg0)
   {
      Debug.Log("Toggling value changed " + arg0);
   }

   private void OffBtnClick()
   {
      switchBtn.IsOn = false;
      toggleBtn.isOn = false;  
   }

   private void OnBtnClick()
   {
      switchBtn.IsOn = true;
      toggleBtn.isOn = true; 
   }

   public void OnSwitchEvent(bool state)
   {
      if (state)
      {
         Debug.Log("开……");
      }
      else
      {
         Debug.Log("关……");
      }
   }
   
   private void Start()
   {
      // TestStrHandle();
      TestJsonHandle();
   }

   private void TestJsonHandle()
   {
      string oStr = "{\"Code\":100,\"ErrorCode\":1220,\"recordData\":{\"record\":true,\"savePath\":\"test path\"}}";
      NetRecordArgs args = new NetRecordArgs
      {
         record = true,
         savePath = "test path"
      };

      NetVTuberArgs vt = new NetVTuberArgs
      {
         code = 100,
         errorCode = 1220,
         recordData = args
      };

      string str = JsonConvert.SerializeObject(vt);
      NetVTuberArgs ob = JsonConvert.DeserializeObject<NetVTuberArgs>(oStr);
      
      Debug.Log(str);
      Debug.Log(ob.recordData.savePath);

   }

   private void TestStrHandle()
   {
      string message = @"使用 Unity Editor 可创建 2D 和 3D 游戏、应用程序和体验。请从 unity.cn 下载  Editor。

      Unity 用户手册可帮助您了解如何使用 Unity Editor 及其相关服务。您可以从头到尾阅读该手册，或将其用作参考。

      如果这是第一次使用 Unity，请查看有关使用 Unity 的介绍性文档，并观看 Unity 教程。   ";
      Debug.Log(message);
      
      string  describe = message.Replace("\n", "").Replace(" ","").Replace("\t","").Replace("\r","");
      Debug.Log(describe);
      
      string str = Regex.Replace(describe, @"[\r\n]", ""); 
      Debug.Log(str);
      
      string trimStr = message.Trim();
   }
}
